package com.example.demo.mapper;

import com.example.demo.model.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author redjava
 * @create 2021-07-21 17:20
 */
@Mapper
public interface QuestionMapper {
    @Select("select * from question where id=#{id}")
    Question getById(Integer id);

    @Insert("insert into question(title,description,gmt_create,gmt_modified,creator,tag) values(#{title},#{description},#{gmtCreate},#{gmtModified},#{creator},#{tag})")
    void create(Question question);

    @Select("select * from question")
    List<Question> list();

    @Select("select count(1) from question")
    int count();

    @Select("select * from question where creator=#{id}")
    List<Question> listById(Integer id);

    @Select("select count(1) from question where creator=#{id}")
    int countbyId(Integer id);

    @Update("update question set title=#{title},description=#{description},tag=#{tag},gmt_modified=#{gmtModified} where id=#{id}")
    int update(Question question);


    @Update("update question set view_count=view_count+1 where id=#{id}")
    void addViewCount(@Param("id") Integer id);


}
